package com.kly.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回类
 * @author admin
 * @date 2025/2/17
 */
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -4580082853295962385L;

    private int code;

    private T data;

    private String message;

    private String description;

    /**
     * success方法
     */
    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.setMessage("ok");
        result.setCode(0);
        result.setDescription("ok");
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(0);
        result.setMessage("ok");
        result.setData(data);
        result.setDescription("ok");
        return result;
    }


    /**
     * error
     */
    public static <T> Result<T> error(ErrorCode errorCode) {
        Result<T> result = new Result<>();
        result.setCode(errorCode.getCode());
        result.setMessage(errorCode.getMessage());
        result.setDescription(errorCode.getDescription());
        return result;
    }

    public static <T> Result<T> error(Integer code, String message, String description) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setDescription(description);
        return result;
    }


}
